

*This file creates the tables regarding occupational and educational changes for over and under 25 when the reparations started as well as the graphs by 5-year cohorts in education and occupation.


global municipality mun39


/////////////////////////////////
*--Input 1950 census data
/////////////////////////////////


*Import the ready-made 1950 population census
use "W:\Matti M\vl50.dta" , clear








*-- Cleaning the 1950 population census data

destring JNRO50, gen(id)
destring PIKA50, gen(age50)
drop PIKA50

label var age50 "Age in 1950"
destring age50, replace
gen byear=1950-age50


rename sp fem
destring fem, replace
replace fem=fem-1
 

rename TOLA50 ind50
label var ind50 "Industry in 1950"
destring ind50, replace


rename AKUNU50 mun50
label var mun50 "Municipality of residence, 1950"
rename sykunu mun_birth
label var mun_birth "Municipality of birth"
rename AKUNU39 mun39
label var mun39 "Municipality of residence, 1939"

rename AMAS50 occstat50
label var occstat50 "Occupational status 1950 (AMAS50)"
destring occstat50, replace
label def occstat50 0 "Entrepeneur with employees" 1 "Entrepeneur wo/ employees" 2 "Manager" 3 "White-collar worker" 4 "Blue-collar worker" ///
	5 "Ass fam: white-collar" 6 "Ass fam: blue-collar"  7 "Ass fam: white or blue" 9 "Out of labor force"
label val occstat50 occstat50
tab occstat50


gen blue_collar=(occstat50==4)
gen unemployed=(occstat50==9)


rename KOULU50 school50
label var school50 "Type of school in 1950"
replace school50="99" if school50=="X"
destring school50, replace
label def school50 0 "Kansakoulu" 1 "Oppikoulu" 2 "Korkeakoulu" 3 "Kansan- ja ty򶤥nopistot" ///
		4 "Kansakouluopettajaseminaarit" 5 "MMK oppilaitokset" 6 "Kauppaoppilaitokset" 7 "Tekniset oppilaitokset" ///
		8 "Muut ammatilliset" 9 "Muut, tuntematon" 99 "not in school", add
label val school50 school50		
tab school50 if school50!=99

rename SITA50 edu50
destring edu50, replace
label var edu50 "Education in 1950"
label def edu50 1 "Kansakoulu" 2 "Keskikoulu" 3 "Ylioppilas" 9 "None, unknown", add
label val edu50 edu50
tab byear edu50


gen ylioppilas=(edu50==3)
gen inschool=(school50!=99)
gen inuni=(school50==2)
gen intrade=(school50==7|school50==8)



gen agriback=(TOLA39=="01")
egen skunta50=group(mun_birth)
egen akunta50=group(mun50)
egen akunta39=group(mun39)
gen agri50_individual=(ind50<19)
gen leave_agri_individual=(ind50>19)


rename TOLA39 ind39
label var ind39 "Industry in 1939"
destring ind39, replace
gen agri39=(ind39==1)


gen tutk50_1=substr(TUTK50,1,1)

*Drop those that can't be linked
drop if shnro==""

count
keep shnro agriback age50 fem edu50 mun39 byear JNRO50 TUTK50 school50 tutk50_1
tempfile data50 
save `data50' 


/////////////////////////////////
**Input 1970 population census data
/////////////////////////////////


*Import the ready-made 1970 population census
use shnro ktutk vuosi using "D:\ready-made\FOLK_vl_7085\vl7085_1.dta" , clear



*Extract highest degree between 1970 and 1975
drop if shnro==""
drop if ktutk=="999999"
gen ktutk1=substr(ktutk,1,1)
gen ktutk2=substr(ktutk,1,2)
keep if vuosi<1980
destring ktutk1 ktutk2 ktutk, replace 
collapse (max) ktutk ktutk1 ktutk2, by(shnro)
rename ktutk1 ktutk1_all
rename ktutk2 ktutk2_all
rename ktutk ktutk_all
tempfile degree
save `degree'


*Import the ready-made 1970 population census

use shnro ktutk vuosi saikavv syntyv ika sose using "D:\ready-made\FOLK_vl_7085\vl7085_1.dta" if vuosi==1970 , clear

*Join with the 1950 census information
joinby  shnro using `data50', unmatched(none)


*Join with the degree information
joinby  shnro using `degree', unmatched(master)
drop _merge


*Join with different education codes to link to the degree information
preserve
import delimited "$temp\komu03.csv", varnames(1) clear 
keep koulk  opmast opm95ast uniscle
tostring koulk, gen(ktutk)
tempfile ecodes2
duplicates drop
save `ecodes2'
restore


joinby ktutk using `ecodes2', unmatched(master)
tab _merge
drop _merge


gen degree=(ktutk!="999999")
gen ktutk1=substr(ktutk,1,1)
destring ktutk1, replace
replace ktutk1=0 if ktutk1==.
gen hdegree=(ktutk1>5&ktutk1<9)
gen hdegree2=(ktutk1>6&ktutk1<9)

gen ktutk2=substr(ktutk,1,2)

gen engineer=(ktutk2=="65"|ktutk2=="75")
gen technical_lower=(ktutk2=="35"|ktutk2=="55")


ed ktutk if hdegree==1
gen uk=(substr(ktutk,3,4)=="9999")
gen degree_all=(ktutk1_all!=.)
gen hdegree_all=(ktutk1_all>5&ktutk1_all<9)
gen hdegree2_all=(ktutk1_all>6&ktutk1_all<9)
gen  hdegree_unk=hdegree
replace hdegree_unk=0 if uk==1
gen degree2=(degree==1)
replace degree2=0 if ktutk1==3


gen degree2_all=(ktutk1_all!=.)
egen muni_g=group($municipality)


*Imputed years of education
gen secondary=(ktutk1==3)
gen lowe_tertiary=(ktutk1==5) //merkonomi ym
gen undergraduate=(ktutk1==6) 
gen graduate=(ktutk1==7) 
gen doctoral=(ktutk1==8) 

gen university_aste=(opm95ast==5|opm95ast==6|opm95ast==7|ktutk1==8)

*Define imputed years of education
gen yos=6
replace yos=12 if edu50==3
replace yos=12 if ktutk1==3
replace yos=14 if ktutk1==5
replace yos=15 if ktutk1==6
replace yos=17 if ktutk1==7
replace yos=21 if ktutk1==8



*Join with the incomes
joinby shnro using  "$temp\1970_1975_income_ranks", unmatched(master)


*Join with the war reparations shock to the 1939 municipality
joinby $municipality using "$temp\shiftshare.dta" 



*Define controls
global municontrols  agrishare_1940 manushare_1940  town city 
global municontrols_cohort c.agrishare_1940#age44 c.manushare_1940#age44  city#age44 town#age44 


**Generate age variables
gen age44=age50-6
gen young=(age44<=25)
gen old=(young==0)


*generate standardized values to get the estimates as increase in one SD
gen bartik_standardized_young=bartik_standardized*young
gen bartik_standardized_old=bartik_standardized*old



/////////////////////////////////////
*-- Human capital 1970s
/////////////////////////////////////

*Sample ages
keep if age44<51

gen group1=(age44>=5&age44<=9)
gen group2=(age44>=10&age44<=14)
gen group3=(age44>=15&age44<=19)
gen group4=(age44>=20&age44<=24)
gen group5=(age44>=25&age44<=29)
gen group6=(age44>=30&age44<=34)
gen group7=(age44>=35&age44<=39)
gen group8=(age44>=40&age44<=45)
gen group9=(age4>=46&age44<=50)


forval x=1/9 {
gen b_group`x'=bartik_standardized*group`x'
}

 
*Event study for higher degrees

local treat "b_group1 b_group2 b_group3 b_group4 b_group5 b_group7 b_group8 b_group9"
tempfile model1 
parmby " reghdfe hdegree  `treat'  , a(age44#laani50 fem muni_g age44 $municontrols_cohort) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=6
 gen estimate=0
 gen parm="b_group6"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str
 
 
tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Age in 1944,) title("Estimates on higher degrees") xlabel(1 "5-9" 2 "10-14" 3 "15-19" 4 "20-24" 5 "25-29" 6 "30-34" 7 "35-39" 8 "40-45" 9 "45-50", angle(vertical)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0)) saving(muni_degrees.gph, replace)  
 
graph save "$temp\graphs\cohort_hdegrees_event", replace
graph export "$temp\graphs\cohort_hdegrees_event.eps", replace
 
restore
 
 
*YOS event study 

local treat "b_group1 b_group2 b_group3 b_group4 b_group5 b_group7 b_group8 b_group9"
tempfile model1 
parmby " reghdfe yos  `treat'  , a(age44#laani50 fem muni_g $municontrols_cohort) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=6
 gen estimate=0
 gen parm="b_group6"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str

 
 tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Age in 1944,) title("Estimates on years of education") xlabel(1 "5-9" 2 "10-14" 3 "15-19" 4 "20-24" 5 "25-29" 6 "30-34" 7 "35-39" 8 "40-45" 9 "45-50", angle(vertical)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0)) saving(muni_degrees.gph, replace)  
 
graph save "$temp\graphs\cohort_yos_event", replace
graph export "$temp\graphs\cohort_yos_event.eps", replace
 
restore




local treat "b_group1 b_group2 b_group3 b_group4 b_group5 b_group7 b_group8 b_group9"
tempfile model1 
parmby " reghdfe degree  `treat'  , a(age44#laani50 fem muni_g age44 $municontrols_cohort) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=6
 gen estimate=0
 gen parm="b_group6"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str
 
 
tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Age in 1944,) title("Estimates on all degrees") xlabel(1 "5-9" 2 "10-14" 3 "15-19" 4 "20-24" 5 "25-29" 6 "30-34" 7 "35-39" 8 "40-45" 9 "45-50", angle(vertical)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0))  
 
graph save "$temp\graphs\degree_event", replace
graph export "$temp\graphs\degree_event.eps", replace
 
restore


local treat "b_group1 b_group2 b_group3 b_group4 b_group5 b_group7 b_group8 b_group9"
tempfile model1 
parmby " reghdfe  undergraduate   `treat'  , a(age44#laani50 fem muni_g age44 $municontrols_cohort) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=6
 gen estimate=0
 gen parm="b_group6"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str
 
 
tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Age in 1944,) title("Estimates on undergraduate degrees") xlabel(1 "5-9" 2 "10-14" 3 "15-19" 4 "20-24" 5 "25-29" 6 "30-34" 7 "35-39" 8 "40-45" 9 "45-50", angle(vertical)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0)) saving(muni_degrees.gph, replace)  
 
graph save "$temp\graphs\ug_event", replace
graph export "$temp\graphs\ug_event.eps", replace

restore 


*Table estimation
 
do "$temp\Replication\code\young_treat_dd.do"


/////////////////////////////////////
*-- Occupational groups in 1970
/////////////////////////////////////

*Define occupations using socioeconomic codes
gen sose2=substr(sose,1,2)
gen sose1=substr(sose,1,1)

tab sose1, gen(occ1_)


gen higher_occ=(sose1=="3")
gen lower_occ=(sose1=="4")
gen wc_ex=(sose1=="3"|sose1=="4")
gen Agri=(sose2=="51")

gen production_work=(sose1=="5")
replace production_work=0 if Agri==1


**Event study executive occupation


local treat "b_group1 b_group2 b_group3 b_group4 b_group5 b_group6 b_group7 b_group8 "
tempfile model1 
parmby " reghdfe higher_occ  `treat'  , a(age44#laani50 age44 fem muni_g $municontrols_cohort) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=9
 gen estimate=0
 gen parm="b_group9"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str
 
tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Age in 1944,) title("Estimates on executive occupation") xlabel(1 "5-9" 2 "10-14" 3 "15-19" 4 "20-24" 5 "25-29" 6 "30-34" 7 "35-39" 8 "40-45" 9 "45-50", angle(vertical)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0)) saving(muni_degrees.gph, replace)  
 
graph save "$temp\graphs\cohort_executive_event_2", replace
graph export "$temp\graphs\cohort_executive_event_2.eps", replace
 
restore
 
**Event study production occupation

 
local treat "b_group1 b_group2 b_group3 b_group4 b_group5 b_group6 b_group7 b_group8 "
tempfile model1 
parmby " reghdfe production_work  `treat'  , a(age44#laani50 age44 fem muni_g $municontrols_cohort) cl(muni_g) " , lab saving(`"`model1'"', replace) idn(1) ids(Unadjusted)

 preserve
 clear all
 set obs 1
 gen group=9
 gen estimate=0
 gen parm="b_group9"
 gen min95=0
 gen max95=0
 append using `model1'
 keep if regexm(parm,"^b_group*")
 gen group_str=substr(parm,-1,1)
 destring group_str, replace  
 sort group_str

 
tw (scatter estimate group_str, msize(medium) mcolor(dknavy)) (rspike min95 max95 group_str, lcolor(dknavy)), xsize(6) ysize(4) xtitle(Age in 1944,) title("Estimates on production occupation") xlabel(1 "5-9" 2 "10-14" 3 "15-19" 4 "20-24" 5 "25-29" 6 "30-34" 7 "35-39" 8 "40-45" 9 "45-50", angle(vertical)) plotregion(lcolor(black)) graphregion(lcolor(black) fcolor(white) color(white))  legend(off)  ytitle("", margin(0 1 0 0)) saving(muni_degrees.gph, replace)  
 
graph save "$temp\graphs\cohort_production_event_2", replace
graph export "$temp\graphs\cohort_production_event_2.eps", replace
 
restore
  
**Create table  
 
do "$temp\Replication\Code\young_treat_dd_occu.do"
 
save "$temp\old_young_temp.dta", replace
 

****
*Robustness table
 
preserve
do "$temp\Replication\Code\robust_old_young.do"
restore

*****************
**Sample for Bartik robustness
*****************

gen ind=1
preserve
keep  if young==1 
collapse $municontrols  bartik_standardized yos income_rank laani50 (sum) ind , by(mun39)
rename ind wei
save "$temp\bartik_young", replace
restore



/////////////////////////////////////
*Upward mobility analysis
/////////////////////////////////////


preserve
drop _merge

count
joinby JNRO50 using  "$temp\father_link_1950_UM", unmatched(master)
count
drop _merge


duplicates drop

*Clean the data of unlikely observations
drop if age50_head<age50
drop if age50_head<25


replace hdegree=1 if hdegree2==1


gen bartik_noedu=bartik_standardized*no_edu_head
gen bartik_elementary=bartik_standardized*kansa_edu_head


keep if young==1

tempfile um um_sample
save `um'
gen weis=1
keep if no_edu_head==1
collapse (sum) weis, by(mun39)
save `um_sample'
use `um', clear
joinby mun39 using `um_sample'
*Only one in the municipality
drop if weis<2



************************
*Low educated parents sample
************************


*income rank

reghdfe income_rank bartik_standardized    $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store rank1
sum income_rank if no_edu_head==1
estadd scalar ymean=r(mean)

reghdfe income_rank bartikhs_st bartikls_st    $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store rank2
sum income_rank if no_edu_head==1
estadd scalar ymean=r(mean)


*years of schooling

reghdfe yos bartik_standardized    i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store yos1
sum yos if no_edu_head==1
estadd scalar ymean=r(mean)

reghdfe yos bartikhs_st bartikls_st    i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store yos2
sum yos if no_edu_head==1
estadd scalar ymean=r(mean)



*Higher degree

reghdfe hdegree bartik_standardized    i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store hdegree1
sum hdegree if no_edu_head==1
estadd scalar ymean=r(mean)


reghdfe hdegree bartikhs_st bartikls_st     i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store hdegree2
sum hdegree if no_edu_head==1
estadd scalar ymean=r(mean)


*executive

reghdfe higher_occ bartik_standardized    i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store higher_occ1
sum higher_occ if no_edu_head==1
estadd scalar ymean=r(mean)

reghdfe higher_occ bartikhs_st bartikls_st      i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store higher_occ2
sum higher_occ if no_edu_head==1
estadd scalar ymean=r(mean)


*white collar 

reghdfe lower_occ bartik_standardized    i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store lower_occ1
sum lower_occ if no_edu_head==1
estadd scalar ymean=r(mean)

reghdfe lower_occ bartikhs_st bartikls_st     i.edu50_head  $municontrols if no_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store lower_occ2
sum lower_occ if no_edu_head==1
estadd scalar ymean=r(mean)


labe var bartik_standardized "Exposure"
labe var bartikhs_st "High-skill Exposure "
labe var bartikls_st "Low-skill Exposure "


esttab rank1 rank2 yos1 yos2 hdegree1 hdegree2 lower_occ1 lower_occ2 higher_occ1 higher_occ2    ///
using "$temp\tables\TABLE_upward_mobility_panelA.tex", ///
mgroups("Income Rank" "Years Schooling"  "Higher Degree"  "White Collar" "Executive", pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(bartik_standardized bartikhs_st bartikls_st) nonotes ///
b(%9.3f) se(%9.3f)  stats(N  ymean, fmt(0 3) layout(@ @) ///
labels("N"  "Y mean")) label star(* .1 ** .05 *** .01) nodepvars nomtitle

est clear

************************
*Higher educated parents sample
************************


*income rank

reghdfe income_rank bartik_standardized    $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store rank1
sum income_rank if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


reghdfe income_rank bartikhs_st bartikls_st     $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store rank2
sum income_rank if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

*Years of schooling


reghdfe yos bartik_standardized    i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store yos1
sum yos if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

reghdfe yos bartikhs_st bartikls_st    i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store yos2
sum yos if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


*hdegree

reghdfe hdegree bartik_standardized    i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store hdegree1
sum hdegree if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


reghdfe hdegree bartikhs_st bartikls_st     i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store hdegree2
sum hdegree if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


*executive

reghdfe higher_occ bartik_standardized    i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store higher_occ1
sum higher_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

reghdfe higher_occ bartikhs_st bartikls_st     i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store higher_occ2
sum higher_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


*white collar 

reghdfe lower_occ bartik_standardized    i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store lower_occ1
sum lower_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

reghdfe lower_occ bartikhs_st bartikls_st    i.edu50_head  $municontrols if keski_edu_head==1|yli_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store lower_occ2
sum lower_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


labe var bartik_standardized "Exposure"
labe var bartikhs_st "High-skill Exposure "
labe var bartikls_st "Low-skill Exposure "

esttab rank1 rank2 yos1 yos2 hdegree1 hdegree2 lower_occ1 lower_occ2 higher_occ1 higher_occ2      ///
using "$temp\tables\TABLE_upward_mobility_panelB.tex", ///
mgroups("Income Rank" "Years Schooling" "Higher degree" "White Collar"  "Executive", pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(bartik_standardized bartikhs_st bartikls_st ) nonotes ///
b(%9.3f) se(%9.3f)  stats(N  ymean, fmt(0 3) layout(@ @) ///
labels("N"  "Y mean")) label star(* .1 ** .05 *** .01) nodepvars nomtitle


est clear

*income rank

reghdfe income_rank bartik_standardized    $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store rank1
sum income_rank if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

reghdfe income_rank bartikhs_st bartikls_st     $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store rank2
sum income_rank if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

*yos

reghdfe yos bartik_standardized    i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store yos1
sum yos if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

reghdfe yos bartikhs_st bartikls_st    i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store yos2
sum yos if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)



*hdegree

reghdfe hdegree bartik_standardized    i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store hdegree1
sum hdegree if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


reghdfe hdegree bartikhs_st bartikls_st     i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store hdegree2
sum hdegree if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


*executive


reghdfe higher_occ bartik_standardized    i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store higher_occ1
sum higher_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


reghdfe higher_occ bartikhs_st bartikls_st     i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store higher_occ2
sum higher_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


*white collar 


reghdfe lower_occ bartik_standardized    i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store lower_occ1
sum lower_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)

reghdfe lower_occ bartikhs_st bartikls_st    i.edu50_head  $municontrols if kansa_edu_head==1, a(fem age50 laani50) cl(muni_g) 
estadd local g "No education"
estadd local regi "\checkmark"
estimates store lower_occ2
sum lower_occ if keski_edu_head==1|yli_edu_head==1
estadd scalar ymean=r(mean)


labe var bartik_standardized "Exposure"
labe var bartikhs_st "High-skill Exposure "
labe var bartikls_st "Low-skill Exposure "

esttab rank1 rank2 yos1 yos2 hdegree1 hdegree2 lower_occ1 lower_occ2 higher_occ1 higher_occ2      ///
using "$temp\tables\TABLE_upward_mobility_panelC.tex", ///
mgroups("Income Rank" "Years Schooling" "Higher degree" "White Collar"  "Executive", pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(bartik_standardized bartikhs_st bartikls_st ) nonotes ///
b(%9.3f) se(%9.3f)  stats(N  ymean, fmt(0 3) layout(@ @) ///
labels("N"  "Y mean")) label star(* .1 ** .05 *** .01) nodepvars nomtitle



/////////////////////////////////////
*Robustness checks UM
/////////////////////////////////////

do "$temp\Replication\Code\robustness_UM.do"


/////////////////////////////////////
*-- Parent income control Table A.3
/////////////////////////////////////


gen ln_parent=ln(svatv_head)

replace svatv_head=svatv_head/1000

reghdfe yos bartik_standardized  $municontrols  if income_rank_head!=., a(byear fem laani50) cl(muni_g)
estimates store yos1
sum yos if income_rank_head!=.
estadd scalar ymean=r(mean)

reghdfe yos bartik_standardized  income_rank_head $municontrols   if income_rank_head!=., a(byear fem laani50) cl(muni_g)
estimates store yos2
sum yos if income_rank_head!=.
estadd scalar ymean=r(mean)

reghdfe yos bartik_standardized  svatv_head $municontrols  , a(byear fem laani50) cl(muni_g)
estimates store yos3
sum yos if income_rank_head!=.
estadd scalar ymean=r(mean)

reghdfe degree bartik_standardized  $municontrols  if income_rank_head!=., a(byear fem laani50) cl(muni_g)
estimates store d1
sum degree if income_rank_head!=.
estadd scalar ymean=r(mean)

reghdfe degree bartik_standardized  income_rank_head $municontrols  , a(byear fem laani50) cl(muni_g)
estimates store d2
sum degree if income_rank_head!=.
estadd scalar ymean=r(mean)

reghdfe degree bartik_standardized  svatv_head $municontrols  , a(byear fem laani50) cl(muni_g)
estimates store d3
sum degree if income_rank_head!=.
estadd scalar ymean=r(mean)


reghdfe hdegree bartik_standardized  $municontrols  if income_rank_head!=., a(byear fem laani50) cl(muni_g)
estimates store h1
sum hdegree if income_rank_head!=.
estadd scalar ymean=r(mean)

reghdfe hdegree bartik_standardized  income_rank_head $municontrols   if income_rank_head!=., a(byear fem laani50) cl(muni_g)
estimates store h2
sum hdegree if income_rank_head!=.
estadd scalar ymean=r(mean)


reghdfe hdegree bartik_standardized  svatv_head $municontrols  , a(byear fem laani50) cl(muni_g)
estimates store h3
sum hdegree if income_rank_head!=.
estadd scalar ymean=r(mean)


labe var bartik_standardized "Exposure"

label var income_rank_head "Father income rank 1970s"
label var svatv_head "Father income 1970s"
label var ln_parent "Father ln income 1970s"


esttab  yos1 yos2 yos3 d1 d2 d3 h1 h2 h3 ///
using "$temp\tables\TABLE_parent_income.tex", ///
mgroups("Years Schooling" "Degree" "Higher Degree", pattern(1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(bartik_standardized income_rank_head svatv_head) nonotes ///
b(%9.3f) se(%9.3f)  stats(N  ymean, fmt(0 3) layout(@ @) ///
labels("N"  "Y mean")) label star(* .1 ** .05 *** .01) nodepvars nomtitle


/////////////////////////////////////
**Sample for Bartik robustness
/////////////////////////////////////

keep  if no_edu_head==1&young==1 
collapse $municontrols  yos income_rank laani50 bartik_standardized (sum) ind , by(mun39)
rename ind wei
save "$temp\bartik_young_UM", replace
restore


/////////////////////////////////////
*-- heterogeneity baseline outcomes
/////////////////////////////////////

drop _merge
count
joinby JNRO50 using  "$temp\father_link_1950_UM", unmatched(master)
count

duplicates drop

*Remove unlikely observations
drop if age50_head<age50
drop if age50_head<25

preserve
keep if age50>40
collapse  yos, by(muni_g)
rename yos yos_muni
sum yos_muni
tempfile edu
save `edu'
restore

drop _merge
joinby muni_g using `edu', unmatched(master)


replace railway=(railway>0)

*By median values
gen high_income=(average_incometax_38>19.43981)
gen high_yos=(yos_muni> 6.622553)

gen bartik_rail=railway*bartik_standardized
gen bartik_income=high_income*bartik_standardized
gen bartik_yos=high_yos*bartik_standardized



*yos

reghdfe  yos   bartik_standardized high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-25"
estimates store yos1
sum yos if young==1
estadd scalar ymean=r(mean)

reghdfe  yos   bartik_standardized bartik_income high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30"
estimates store yos2
sum yos if young==1
estadd scalar ymean=r(mean)

reghdfe  yos   bartik_standardized bartik_rail high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30"
estimates store yos3
sum yos if young==1
estadd scalar ymean=r(mean)

reghdfe  yos   bartik_standardized bartik_yos high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30"
estimates store yos4
sum yos if young==1
estadd scalar ymean=r(mean)

*rank income

reghdfe  income_rank   bartik_standardized high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30 + Parent No education"
estimates store income_rank1
sum income_rank if no_edu_head==1&young==1
estadd scalar ymean=r(mean)

reghdfe  income_rank   bartik_standardized bartik_income high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30 + Parent No education"
estimates store income_rank2
sum income_rank if no_edu_head==1&young==1
estadd scalar ymean=r(mean)

reghdfe  income_rank   bartik_standardized bartik_rail high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30 + Parent No education"
estimates store income_rank3
sum income_rank if no_edu_head==1&young==1
estadd scalar ymean=r(mean)

reghdfe  income_rank   bartik_standardized bartik_yos high_yos high_income railway $municontrols  if no_edu_head==1&young==1, a(byear fem laani50) cl(muni_g)
estadd local g "11-30 + Parent No education"
estimates store income_rank4
sum income_rank if no_edu_head==1&young==1
estadd scalar ymean=r(mean)


labe var bartik_standardized "Exposure"
labe var bartik_income "Exposure x High income"
labe var bartik_rail "Exposure x Railway"
labe var bartik_yos "Exposure x High Education"


esttab yos1 yos2 yos3 yos4 income_rank1 income_rank2 income_rank3 income_rank4 ///
using "$temp\tables\TABLE_heterogeneity_1.tex", ///
mgroups("Years Schooling"  "Income Rank", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) ///
span erepeat(\cmidrule(lr){@span}) ) ///
replace keep(bartik_standardized bartik_income bartik_rail bartik_yos) nonotes ///
b(%9.3f) se(%9.3f)  stats(N  ymean , fmt(0 3) layout(@ @) ///
labels("N"  "Y mean")) label star(* .1 ** .05 *** .01) nodepvars nomtitle



preserve
keep bartik_yos bartik_rail bartik_income high_yos high_income railway mun39
collapse bartik_yos bartik_rail bartik_income high_yos high_income railway, by(mun39)
save "$temp\heterogeneity", replace
restore



